package jmetal.problems.glt;

import jmetal.core.Problem;
import jmetal.core.Solution;
import jmetal.core.Variable;
import jmetal.encodings.solutionType.RealSolutionType;
import jmetal.util.JMException;

@SuppressWarnings("serial")
public class GLT3 extends Problem {

	public GLT3() {
		this.setNumberOfVariables(10);
		this.setSolutionType(new RealSolutionType(this));
		this.numberOfObjectives_ = 2;
		problemName_ = "GLT3";
		numberOfConstraints_= 0;
	    lowerLimit_ = new double[numberOfVariables_];
	    upperLimit_ = new double[numberOfVariables_];
	      lowerLimit_[0] = 0;
	      upperLimit_[0] = 1.0;
	    for (int var = 1; var < numberOfVariables_; var++){
	      lowerLimit_[var] = -1.0;
	      upperLimit_[var] = 1.0;
	    } //for
	}
	
	@Override
	public void evaluate(Solution solution) throws JMException {
		Variable[] var = solution.getDecisionVariables();
		double[] f = new double[2];
		double g = 0.0;
		for (int i = 1; i < numberOfVariables_; i++) {
			double t = 2.0 * Math.PI * var[0].getValue()
					+ (double) (i) / (double) (numberOfVariables_) * Math.PI;
			g += Math.pow( var[i].getValue() - Math.sin(t), 2.0);
		}
		g += 1.0;
		f[0] = g * var[0].getValue();
		if (f[0] <= 0.05)
			f[1] = g * (1.0 - 19.0 * var[0].getValue());
		else
			f[1] = g * ((1.0 - var[0].getValue()) / 19.0);

		solution.setObjective(0, f[0]);
		solution.setObjective(1, f[1]);
	}

}
